package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.safe.domain.dto.EntityIdsDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.BizCatalog;
import com.ruoyi.safe.service.IBizCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业内资料目录Controller------>张鹏
 * 
 * @author ruoyi
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/catalog/catalog")
public class BizCatalogController extends BaseController
{
    @Autowired
    IBizCatalogService bizCatalogService;

    /**
     * 查询业内资料目录列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCatalog bizCatalog)
    {
        startPage();
        List<BizCatalog> list = bizCatalogService.selectBizCatalogList(bizCatalog);
        return getDataTable(list);
    }

    /**
     * 导出业内资料目录列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:export')")
    @Log(title = "业内资料目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCatalog bizCatalog)
    {
        List<BizCatalog> list = bizCatalogService.selectBizCatalogList(bizCatalog);
        ExcelUtil<BizCatalog> util = new ExcelUtil<BizCatalog>(BizCatalog.class);
        util.exportExcel(response, list, "业内资料目录数据");
    }

    /**
     * 获取业内资料目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCatalogService.selectBizCatalogById(id));
    }

    /**
     * 新增业内资料目录
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:add')")
    @Log(title = "业内资料目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCatalog bizCatalog)
    {
        return toAjax(bizCatalogService.insertBizCatalog(bizCatalog));
    }

    /**
     * 修改业内资料目录
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:edit')")
    @Log(title = "业内资料目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCatalog bizCatalog)
    {
        return toAjax(bizCatalogService.updateBizCatalog(bizCatalog));
    }

    /**
     * 删除业内资料目录
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:remove')")
    @Log(title = "业内资料目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(bizCatalogService.deleteBizCatalogById(id));
    }

    /**
     * 批量删除业内资料目录
     */
    @PreAuthorize("@ss.hasPermi('catalog:catalog:remove')")
    @Log(title = "业内资料目录", businessType = BusinessType.DELETE)
    @PostMapping("/deleteByIds")
    public AjaxResult deleteByIds(@RequestBody EntityIdsDTO entityIdsDTO) {
        if(entityIdsDTO.getIds().length > 0){
            return toAjax(bizCatalogService.deleteBizCatalogByIds(entityIdsDTO.getIds()));
        }else {
            throw new ServiceException("id集合不能为空");
        }
    }
}
